﻿using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
using System.Linq;
using System.Web;
using MySQL.Db;

namespace Gollie.DataTables
{
	public class VendorOffersItem
	{
		public string UserFullName { get; set; }
		public uint OfferId { get; set; }
		public uint UserId { get; set; }
		public decimal Credit { get; set; }
		public decimal Price { get; set; }
		public int NumberMax { get; set; }
		public uint ExpiresAfter { get; set; }
		public DateTime ValidFrom { get; set; }
		public DateTime EntryDate { get; set; }
		public string Description { get; set; }
		public int NumberSold { get; set; }
		public DateTime ValidTo { get; set; }
	}

	public class VendorOffers : BaseBindable<VendorOffersItem>
	{
		public VendorOffers(UserInfo userInfo)
		{
			ResultSet resultSet = Database.Queries.GetVendorOffers(userInfo);

			this.AddDetails(resultSet);
		}

		private void AddDetails(ResultSet resultSet)
		{
			int numRows = resultSet.Count;

			for (int i = 0; i < numRows; i++)
			{
				this.Add(new VendorOffersItem()
				{
					UserFullName = UserInfo.GetFullName(resultSet.GetString(i, "initials"), resultSet.GetString(i, "infix"), resultSet.GetString(i, "lastname")),
					OfferId = resultSet.GetUInt32(i, "id"),
					UserId = resultSet.GetUInt32(i, "userid"),
					Credit = resultSet.GetDecimal(i, "credit"),
					Price = resultSet.GetDecimal(i, "price"),
					NumberMax = resultSet.GetInt32(i, "numbermax"),
					ExpiresAfter = resultSet.GetUInt32(i, "expiresafter"),
					ValidFrom = resultSet.GetDateTime(i, "validfrom"),
					EntryDate = resultSet.GetDateTime(i, "entrydate"),
					Description = resultSet.GetString(i, "description"),
					NumberSold = resultSet.GetInt32(i, "numbersold"),
					ValidTo = resultSet.GetDateTime(i, "validto")

				});
			}
		}
	}
}